package com.esri.core.analysis;

import com.esri.android.map.Layer;
import com.esri.core.geometry.Point;
import com.esri.core.internal.util.c;
import com.esri.core.internal.util.g;
import com.esri.core.renderer.UniqueValueRenderer;
import java.io.File;
import java.io.FileNotFoundException;

/* loaded from: classes.dex */
public class LineOfSight implements Function {
    private long a;
    private final String b = "Line of Sight";

    @Override // com.esri.core.analysis.Function
    public String getName() {
        return "Line of Sight";
    }

    native void nativeClose(long j);

    native long nativeCreate(String str, String str2);

    native double[] nativeGetObserver(long j);

    native double nativeGetObserverZOffset(long j);

    native double[] nativeGetTarget(long j);

    native double nativeGetTargetZOffset(long j);

    native void nativeSetObserver(long j, double d, double d2);

    native void nativeSetObserverZOffset(long j, double d);

    native void nativeSetSightRenderers(long j, String str, String str2);

    native void nativeSetTarget(long j, double d, double d2);

    native void nativeSetTargetZOffset(long j, double d);

    static {
        if (System.getProperty("java.runtime.name").contains("Android")) {
            System.loadLibrary("RSSupport");
            System.loadLibrary("rs.main");
            System.loadLibrary("render_script_analysis");
        }
    }

    public LineOfSight(String str) throws IllegalArgumentException, FileNotFoundException, RuntimeException {
        this.a = 0L;
        System.out.println("The LineOfSight class is marked as Beta functionality at the 10.2.4 release. Please send us your feedback on this functionality through the public forums. Please see license information.");
        if (g.a(str)) {
            throw new IllegalArgumentException("The path to the raster data cannot be null or empty string.");
        }
        if (!new File(str).exists()) {
            throw new FileNotFoundException("Could not find file located at: " + str);
        }
        try {
            this.a = nativeCreate(str, c.a().getAbsolutePath());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override // com.esri.core.analysis.Function
    public long getId() {
        return this.a;
    }

    public Point getObserver() {
        double[] nativeGetObserver;
        long j = this.a;
        if (j == 0 || (nativeGetObserver = nativeGetObserver(j)) == null || nativeGetObserver.length != 3) {
            return null;
        }
        return new Point(nativeGetObserver[0], nativeGetObserver[1], nativeGetObserver[2]);
    }

    public void setObserver(Point point) {
        if (this.a == 0 || point == null || point.isEmpty()) {
            return;
        }
        nativeSetObserver(this.a, point.getX(), point.getY());
    }

    public double getObserverZOffset() {
        long j = this.a;
        if (j != 0) {
            return nativeGetObserverZOffset(j);
        }
        return -1.0d;
    }

    public void setObserverZOffset(double d) {
        long j = this.a;
        if (j != 0) {
            nativeSetObserverZOffset(j, d);
        }
    }

    public Point getTarget() {
        double[] nativeGetTarget;
        long j = this.a;
        if (j == 0 || (nativeGetTarget = nativeGetTarget(j)) == null || nativeGetTarget.length != 3) {
            return null;
        }
        return new Point(nativeGetTarget[0], nativeGetTarget[1], nativeGetTarget[2]);
    }

    public void setTarget(Point point) {
        if (this.a == 0 || point == null || point.isEmpty()) {
            return;
        }
        nativeSetTarget(this.a, point.getX(), point.getY());
    }

    public double getTargetZOffset() {
        long j = this.a;
        if (j != 0) {
            return nativeGetTargetZOffset(j);
        }
        return -1.0d;
    }

    public void setTargetZOffset(double d) {
        long j = this.a;
        if (j != 0) {
            nativeSetTargetZOffset(j, d);
        }
    }

    public void setSightRenderers(UniqueValueRenderer uniqueValueRenderer, UniqueValueRenderer uniqueValueRenderer2) {
        try {
            if (this.a != 0) {
                nativeSetSightRenderers(this.a, a(uniqueValueRenderer) ? uniqueValueRenderer.toJson() : null, a(uniqueValueRenderer2) ? uniqueValueRenderer2.toJson() : null);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private boolean a(UniqueValueRenderer uniqueValueRenderer) {
        return uniqueValueRenderer != null && uniqueValueRenderer.getUniqueValueInfos() != null && uniqueValueRenderer.getUniqueValueInfos().size() > 0 && "visibility".equals(uniqueValueRenderer.getField1());
    }

    public Layer getOutputLayer() {
        return new a(this);
    }

    @Override // com.esri.core.analysis.Function
    public void dispose() {
        long j = this.a;
        if (j != 0) {
            nativeClose(j);
            this.a = 0L;
        }
    }

    protected void finalize() throws Throwable {
        super.finalize();
        dispose();
    }
}
